package utils;

public class Stats 
{

	/**
	@param a Analyzer
	@return the size of the arrayList
	*/
	public static int count(Analyzer a)	
	{
	return a.requestData().size(); 	
	}
	
	/**
	@param a the Analyzer
	@return the Sum of the elements in the arrayList
	*/
	public static double sum(Analyzer a)
	{
	double listSum=0;
	for (Double listElement : a.requestData())
	{
		listSum = listSum + listElement;
	}
	return Math.rint(listSum);
	}
	
	/**
	@param a Analyzer
	@return the average of the elements in the ArrayList
	*/
	public static double average(Analyzer a)
	{
		double listAverage=0;
		if (count(a) > 0)
		{
			listAverage= sum(a) / count(a);
			return Math.rint(listAverage);
		}
		else 
		{
			return Double.NaN;
		}
	}
	
	/**
	@param a the Analyzer
	@return the Standard Deviation of the elements in the ArrayList
	*/
	public static double stdDeviation(Analyzer a)
	{
		if (count(a) > 2)
		{
			double listStdDeviation = 0;
			double StDevAverageMinusSum = sum(a) - average(a);
			double StDevNumerator = (StDevAverageMinusSum * StDevAverageMinusSum);
			double StDevDenomenator = (count(a) - 1); 
			double StDevFraction = (StDevNumerator / StDevDenomenator);
			listStdDeviation = Math.sqrt(StDevFraction);
			return Math.rint(listStdDeviation);
		}
	else
		{
		return Double.NaN;
		}
	}
	
	/**
	@param a the Analyzer
	@return the minimum value of the ArrayList
	*/
	public static double min(Analyzer a)
	{
		double listMin = Double.MAX_VALUE;
		for (Double listElement : a.requestData())
		{
			if (listMin > listElement)
			{
				listMin = listElement;
			}
		}
		return Math.rint(listMin);
	}
	
	/**
	@param a the Analyzer
	@return the maximum value of the ArrayList
	*/
	public static double max(Analyzer a)
	{
		double listMax = Double.MIN_VALUE;
		for (Double listElement : a.requestData())
		{
			if (listMax < listElement)
			{
				listMax = listElement;
			}
		}
		return Math.rint(listMax);
	}	
}